package com.ceair.mub2c.payment.payments.utils;

import com.ceair.flight.payment.dto.CashRespContentDto;
import com.ceair.flight.payment.dto.PayResponseDetailDto;
import com.ceair.flight.payment.dto.PayResponseDto;
import com.ceair.flight.payment.dto.PointRespContentDto;
import com.ceair.mub2c.payment.payments.vo.BIG_ORDER;
import com.ceair.mub2c.payment.payments.vo.PASSENGER_INFO;
import com.ceair.mub2c.payment.payments.vo.TEAM_NO;
import com.ceair.mub2c.payment.payments.vo.TICKET_INFO;
import com.ceair.mub2c.payment.payments.vo.TRAVEL_INFO;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * 异步回调,xml转dto工具类
 * 
 * @author Guy
 *
 */
public class XmlToDtoUtils {

    public static void main(String[] args) {
        String msg = "<root><Details><Detail><CmdId>PAYORD</CmdId><RespCode>000000</RespCode><ErrorDesc></ErrorDesc><SCCode>B2BSC1003</SCCode><SubSCCode>SUBB2BSC1001</SubSCCode><PCCode>CC003T</PCCode><SubPCCode>SUBPNR002T</SubPCCode><SCOrdId>tki1tsm03</SCOrdId><SCAcctDate>20160629</SCAcctDate><SysSeqId>2016062900346983</SysSeqId><AcctDate>20160629</AcctDate><SysTime>153017</SysTime><ActualPayAmt>252.00</ActualPayAmt><CurCode>CNY</CurCode><BankCode> </BankCode><PCSysSeqId></PCSysSeqId><PCAcctDate>20160629</PCAcctDate><Resv1></Resv1><Resv2></Resv2><Resv3></Resv3><Resv4></Resv4><Resv5></Resv5><Resv6></Resv6><SignType>MD5</SignType> <SignValue>4AB304DC45B8197E963038FFE940F76E</SignValue></Detail></Details></root>";
        PayResponseDto processResultOfPriceByItinerary = XmlToDtoUtils
                .XmltoDto(msg);
        System.out.println(processResultOfPriceByItinerary);
    }

    /**
     * xml转dto
     * 
     * @param xml
     * @return
     */
    public static PayResponseDto XmltoDto(String xml) {
        xml = PayResponseDetailDto.replaceAttributeName(xml);
        System.out.println("xml解析开始............"+xml);
        XStream xs1 = new XStream(new DomDriver());
        xs1.alias("root", PayResponseDto.class);
        xs1.alias("Detail", PayResponseDetailDto.class);
        xs1.aliasField("Details", PayResponseDto.class, "details");
        xs1.alias("POINT", PointRespContentDto.class);
        xs1.alias("CASH", CashRespContentDto.class);
        xs1.aliasField("RespContent", PayResponseDetailDto.class, "paymentRespContentDtos");

        PayResponseDto base = new PayResponseDto();
        base = (PayResponseDto) xs1.fromXML(xml);
        System.out.println("xml解析结束............"+base);
        return base;
    }
    
    /**
     * dto转xml
     * 
     * @param xml
     * @return
     */
    public static String DtotoXml(BIG_ORDER BIG_ORDER) {
    	XStream xstream = new XStream(); 
        xstream.alias("TICKET_INFO", TICKET_INFO.class); 
        xstream.alias("TRAVEL_INFO", TRAVEL_INFO.class); 
        xstream.alias("PASSENGER_INFO", PASSENGER_INFO.class); 
        xstream.alias("TEAM_NO", TEAM_NO.class); 
        xstream.alias("BIG_ORDER", BIG_ORDER.class);
        String xml = xstream.toXML(BIG_ORDER);
        System.out.println(xml);
		return xml; 
    }


}
